import Mock from 'mockjs'
import getComponentList from './getComponentList'

const Random = Mock.Random

export default function getStatList(page = 1, pageSize = 5) {
  const componentList = getComponentList()

  const res = []

  const from = (page - 1) * pageSize
  const to = page * pageSize

  for (let i = from; i < to; i++) {
    // 一个用户的答卷
    const stat = {
      _id: Random.id(),
    } as any

    // 增加各个组件的 id value
    componentList.forEach(c => {
      const { fe_id, type, props } = c as any

      switch (type) {
        case 'questionInput':
          stat[fe_id] = Random.ctitle()
          break
        case 'questionTextarea':
          stat[fe_id] = Random.ctitle()
          break
        case 'questionRadio':
          stat[fe_id] = props.options[0].text
          break
        case 'questionCheckbox':
          stat[fe_id] = `${props.list[0].text},${props.list[1].text}`
          break
      }
    })

    res.push(stat)
  }

  return res
}
